﻿// <copyright file="UserProfile.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

//All propertiex should be virtual according http://msdn.microsoft.com/en-us/library/dd468057.aspx

namespace CleverCMS.Cms.Data.Entities
{
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Security.Principal;

    [Table("UserProfile")]
    public class UserProfile : CmsObject, IIdentity
    {
        /// <summary>
        /// 
        /// </summary>
        [Required(ErrorMessage = "*")]
        public virtual string Login { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [Required(ErrorMessage = "*")]
        public virtual string DisplayName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [Required(ErrorMessage = "*")]
        [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "*")]
        [DataType(DataType.EmailAddress)]
        public virtual string Email { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [NotMapped]
        [MinLength(6)]
        public virtual string CurrentPassword { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [NotMapped]
        [MinLength(6)]
        public virtual string Password { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [ForeignKey("UserId")]
        public virtual IEnumerable<CmsRating> Ratings { get; set; }

        #region IIdentity Members

        [NotMapped]
        public string Name
        {
            get { return this.Login; }
            set { this.Login = value; }
        }

        [NotMapped]
        public string AuthenticationType
        {
            get { return "CleverCmsAuthentication"; }
        }

        [NotMapped]
        public bool IsAuthenticated
        {
            get { return Id != 0; }
        }

        #endregion
    }
}